import metchonServices from '@/services/metchonService.js';

export default {
	data() {
		return {
			sbxxByQrData: {},
			gzlxOptions: [],
			sblxOptions: [],
			sbztOptions: [{
					label: '正常',
					value: 0
				},
				{
					label: '异常',
					value: 1
				}, {
					label: '其他',
					value: 2
				}],
			fromData: {
				sbbh:'',
				sbzt:'',
				fault:'',
				basis:'',
				term:'',
				analysis:'',
				programme:'',
				yl: "",
				yl1: "",
				yl2: ""
			},
		}
	},
	onShow(){
		console.log('xunjian show')
	},
	onTabItemTap : function(e) {
		this.init();
		console.log('fromData.sbbh',this.fromData.sbbh)
	},
	async onLoad() {
		await this.$store.dispatch('checkLoginAction');
		 this.sblxOptions = await metchonServices.getTypesList();
	},
	methods: {
		init(){
			this.sbxxByQrData = {
				yl: "",
				yl1: "",
				yl2: ""
			};
	
			this.fromData = {
				sbbh:'',
				sbzt:'',
				fault:'',
				basis:'',
				term:'',
				analysis:'',
				programme:'',
				yl: "",
				yl1: "",
				yl2: ""
			};
		},
		async onSaoMiao() {
			const that = this;
			
			// that.sbxxByQrData = await metchonServices.querySbxxByQr('0ef3d8c1e6d94d709008805295b551ee');
			// that.fromData.sbbh = that.sbxxByQrData.sbbh;
			// that.fromData.sbid = that.sbxxByQrData.id;				
			// that.fromData.yl = that.sbxxByQrData.yl;
			// that.fromData.yl1 = that.sbxxByQrData.yl1;
			// that.fromData.yl2 = that.sbxxByQrData.yl2;
			
			// that.gzlxOptions = await metchonServices.getfaultListByType(that.sbxxByQrData.sblx);
			
			// 调起条码扫描
			uni.scanCode({
				onlyFromCamera: false, // 是否只能从相机扫码，不允许从相册选择图片
				scanType: ['qrCode'], // 扫码类型 qrCode二维码
				autoZoom: true, // 是否启用自动放大，默认启用
				success: async function(res) {
					console.log(`扫码结果：${JSON.stringify(res,null,2)}`);
					that.sbxxByQrData = await metchonServices.querySbxxByQr(res.result);
					that.fromData.sbbh = that.sbxxByQrData.sbbh;
					that.fromData.sbid = that.sbxxByQrData.id;				
					that.fromData.yl = that.sbxxByQrData.yl;
					that.fromData.yl1 = that.sbxxByQrData.yl1;
					that.fromData.yl2 = that.sbxxByQrData.yl2;
					
					that.gzlxOptions = await metchonServices.getfaultListByType(that.sbxxByQrData.sblx);
				},
				fail: function(err) {
					console.log(`错误：${err}`);
				},
				complete: function(data) {}
			});
		},
		async onSubmit(){
			if (!this.sbxxByQrData || !this.fromData.sbid ) {
				this.$message.error('请扫描设备');
				return;
			}
			// if (!this.fromData.sbzt && this.fromData.sbzt !== 0) {
			// 	this.$message.error('请选择设备状态');
			// 	return;
			// }
			// if (!this.fromData.fault) {
			// 	this.$message.error('请选择故障类型');
			// 	return;
			// }
			// if (!this.fromData.basis) {
			// 	this.$message.error('请输入援引依据');
			// 	return;
			// }
			// if (!this.fromData.term) {
			// 	this.$message.error('请输入具体条款');
			// 	return;
			// }
			// if (!this.fromData.analysis) {
			// 	this.$message.error('请输入问题分析');
			// 	return;
			// }
			// if (!this.fromData.programme) {
			// 	this.$message.error('请输入解决方案');
			// 	return;
			// }
			
			await metchonServices.inspectionAdd(this.fromData);
			this.$message.success('添加成功')
		}
	}
}